package com.lingyu.jsjx.service.impl;

import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lingyu.jsjx.domain.vo.UserDocumentVO;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.datascope.annotation.DataScope;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.lingyu.jsjx.mapper.UserDocumentMapper;
import com.lingyu.jsjx.domain.UserDocument;
import com.lingyu.jsjx.service.IUserDocumentService;

/**
 * 文档管理Service业务层处理
 *
 * @author ruoyi
 * @date 2025-07-31
 */
@Service
public class UserDocumentServiceImpl extends ServiceImpl<UserDocumentMapper, UserDocument> implements IUserDocumentService {
    @Autowired
    private UserDocumentMapper userDocumentMapper;

    /**
     * 查询文档管理
     *
     * @param wordId 文档管理主键
     * @return 文档管理
     */
    @Override
    public UserDocument selectUserDocumentByWordId(Long wordId) {
        return userDocumentMapper.selectUserDocumentByWordId(wordId);
    }

    /**
     * 查询文档管理列表
     *
     * @param userDocument 文档管理
     * @return 文档管理
     */
    @Override
    @DataScope(deptAlias = "u", userAlias = "w",type = "jsjx")
    public List<UserDocument> selectUserDocumentList(UserDocument userDocument) {
        userDocument.setCreateBy(String.valueOf(SecurityUtils.getUserId()));
        return userDocumentMapper.selectUserDocumentList(userDocument);
    }

    /**
     * 新增文档管理
     *
     * @param userDocument 文档管理
     * @return 结果
     */
    @Override
    public int insertUserDocument(UserDocument userDocument) {
        return baseMapper.insert(userDocument);
    }

    /**
     * 修改文档管理
     *
     * @param userDocument 文档管理
     * @return 结果
     */
    @Override
    public int updateUserDocument(UserDocument userDocument) {
        return baseMapper.updateById(userDocument);
    }

    /**
     * 批量删除文档管理
     *
     * @param wordIds 需要删除的文档管理主键
     * @return 结果
     */
    @Override
    public int deleteUserDocumentByWordIds(Long[] wordIds) {
        return userDocumentMapper.deleteUserDocumentByWordIds(wordIds);
    }

    /**
     * 删除文档管理信息
     *
     * @param wordId 文档管理主键
     * @return 结果
     */
    @Override
    public int deleteUserDocumentByWordId(Long wordId) {
        return userDocumentMapper.deleteUserDocumentByWordId(wordId);
    }

    @Override
    public List<UserDocumentVO> selectSharedDocuments(Long majorId,String wordTitle,String deptId, String categoryId,Long userId) {
        return userDocumentMapper.selectSharedDocuments(majorId,wordTitle,deptId, categoryId,userId);
    }

    @Override
    public List<Map<String, Object>> selectUserDocumentUpDownCount() {
        return userDocumentMapper.selectUserDocumentUpDownCount();
    }
}
